package com.kiell.cubemall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.reactive.config.CorsRegistry;

/**
 * @author HuangZeWei
 * @PackageName com.kiell.cubemall.gateway.config
 * @ClassName CubemallCorsConfigtion
 * @Description
 * @date 2022/1/14 11:04
 */
@Configuration
public class CubemallCorsConfigtion {

    @Bean
    public CorsWebFilter corsWebFilter(){
        CorsConfiguration config = new CorsConfiguration();

        config.setAllowCredentials(true);//可以携带cookie信息
        config.addAllowedOrigin("*");//允许所有的请求地址访问
        config.addAllowedHeader("*");//允许携带所有的请求头信息
        config.addAllowedMethod("*");//允许所有的请求方式

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", config);

       return new CorsWebFilter(source);
    }
}
